package com.rgz.controller.wgController;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rgz.pojo.CaseDiscribe;
import com.rgz.pojo.Caseone;
import com.rgz.pojo.User;
import com.rgz.service.WgService.UserService;

@Controller
public class TroubleController {

	@Autowired
	private UserService userService;


	/**
	 * @param caseDiscribe
	 * @param request
	 * @return
	 */
	@RequestMapping("ccx_photo_in")
	public String whd_login(@ModelAttribute CaseDiscribe caseDiscribe, HttpServletRequest request, Model model) {
		User user = (User) request.getSession().getAttribute("user");
		String userphone = user.getUserphone();

		String orderIdByUUId = null;
		Caseone caseone = new Caseone();

		String idcare = userService.selectByIdcare(caseDiscribe.getIdentity());

		if (idcare == null || idcare == "") {
			return "wzw_wxts";
		}
		request.getSession().setAttribute("policyno", idcare);
		// 判断前端传值
		if (caseDiscribe != null) {

			orderIdByUUId = getOrderIdByUUId();
			caseone.setUserphone(userphone);
			caseone.setCaseno(orderIdByUUId);
			caseone.setEmployeeid(null);
			caseone.setAssessmentstatusonline(null);
			caseone.setStatusid(2);
			caseDiscribe.setCasephone(caseone.getUserphone());
			caseDiscribe.setCaseno(caseone.getCaseno());
			Boolean falg = userService.CaseAndCaseDiscribeByNo(caseone, caseDiscribe);
			if (!falg) {
				return "wzw_basb";
			}
		}
		
		model.addAttribute("caseone", caseone);
		model.addAttribute("caseDiscribe", caseDiscribe);
		return "ccx_photo";
	}

	public static String getOrderIdByUUId() {
		int machineId = 1;
		int hashCodeV = UUID.randomUUID().toString().hashCode();
		if (hashCodeV < 0) {
			hashCodeV = -hashCodeV;
		}
		return machineId + String.format("%015d", hashCodeV);
	}

	@RequestMapping("WGClaimsQuery2")
	public String WGClaimsQuery2() {
		return "WGClaimsQuery2";

	}
	@RequestMapping("WGClaimsQuery")
	public String WGClaimsQuery1() {
		return "WGClaimsQuery";

	}
}
